﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/Dialog.Master" AutoEventWireup="true" CodeBehind="PositionDialogBox.aspx.cs" Inherits="Legazpi.Payroll.Web.PopupBoxes.PositionDialogBox" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript">
    var serviceUrl = '<%=ResolveUrl("~/Webservices/EmployeeWebService.asmx")%>';    
    $(document).ready(function () {
        $('#PositionSubmitButton').click(function () {
            if (!$("#dialogForm").valid()) {
                return false;
            }
            
            var PositionObj = {
                Id: $('#Id').val(),
                Code: $('#PositionCode').val(),
                Description: $('#PositionDesc').val(),
                Incentive: $('#Incentive').val(),
                Retirement: $('#Retirement').val(),
                UniformAllowance: $('#UniformAllowance').val()
            };

            var json = JSON.stringify({ positionItem: PositionObj });
            BlockUI.BlockElementLoading("dialog", "Saving...", true, 4);
            $.ajax({
                type: "POST",
                url: serviceUrl + "/AddPosition",
                data: json,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    var response = eval('(' + data.d + ')');
                    if (response.Success) {
                        alert('Saved!');
                        if (typeof Position === "undefined") {
                            var dropDown = $('#' + Employee.PositionDropdownControlId);
                            dropDown.append("<option value='" + response.PositionItem.Id + "'>" + response.PositionItem.Code + "</option>")                            
                            PopUpDialog.CloseDialog(Employee.PositionPopUpId);
                        } else {
                            PopUpDialog.CloseDialog(Position.PositionUpdatePopUpId);
                            Position.SetRowData(response);
                        }
                    }
                },
                complete: function () {
                    BlockUI.UnBlockElement("dialog");
                }
            });
        });

        $.validator.addMethod('validNumber', function (value, element) {
            var floatRegex = '[-+]?([0-9]*\.[0-9]+|[0-9]+)';
            return (value.match(floatRegex));
        },'Not accept non-numeric');

        $("#dialogForm").validate({
            rules: {
                PositionCode: "required",
                Incentive: {
                    validNumber: true
                },
                Retirement: {
                    validNumber : true
                },
                UniformAllowance: {
                    validNumber : true
                }
            },
            messages: {
                PositionCode: "Please enter Code"                
            }
        });
    });
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Content" runat="server">
           <form id="dialogForm">
            <input type="hidden" id="Id" value="<%=Model.Id %>" />
            <fieldset class="register">
                <legend>Position Details</legend>
                <p>
                    <label for="PositionCode">Code:</label>
                    <input type="text" id="PositionCode" name="PositionCode" class="textEntry" value="<%=Model.Code %>" />
                </p>
                <p>
                    <label for="PositionDesc">Description:</label>
                    <input type="text" id="PositionDesc" maxlength="100" class="textEntry" value="<%=Model.Description %>" />
                </p>
                <p>
                    <label for="Incentive">Incentive:</label>
                    <input type="text" id="Incentive" name="Incentive" maxlength="100" class="textEntry" value="<%=Model.Incentive %>" />
                </p>
                <p>
                    <label for="Retirement">Retirement:</label>
                    <input type="text" id="Retirement" name="Retirement"  class="textEntry" value="<%=Model.Retirement %>" />
                <p>
                    <label for="UniformAllowance">Uniform Allowance:</label>
                    <input type="text" id="UniformAllowance" name="UniformAllowance" class="textEntry" value="<%=Model.UniformAllowance %>" />
                </p>
                </p>
            </fieldset>
            <p class="submitButton">
                <input type="button" id="PositionSubmitButton" value="OK" />
            </p>
            </form>
</asp:Content>
